package com.bbbk.util.word.conf;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.catalina.connector.RequestFacade;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor;

public class MyRequestResponseBodyMethodProcessor implements HandlerMethodReturnValueHandler{
	
	RequestResponseBodyMethodProcessor processor;
	
	public MyRequestResponseBodyMethodProcessor(RequestResponseBodyMethodProcessor processor) {
		this.processor = processor;
	}

	@Override
	public boolean supportsReturnType(MethodParameter returnType) {
		// TODO Auto-generated method stub
		return processor.supportsReturnType(returnType)&&true;
	}

	@Override
	public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest) throws Exception {
		Object nativeRequest2 = webRequest.getNativeRequest();
		if(nativeRequest2 instanceof HttpServletRequest) {
			HttpServletRequest nativeRequest =(HttpServletRequest) nativeRequest2;
			HttpSession session = nativeRequest.getSession();
			System.out.println(nativeRequest.getClass().getName());
		}
		
		if(returnValue!=null&& false) {// 临时写死 不改返回数据
			System.out.println(returnValue);
			returnValue = returnValue.toString()+returnValue;
		}
		processor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
		
	}

}
